home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_087 / autoiconopen / autoiconopen.c < prev   
C/C++ Source or Header  |  1992-05-06  |  8KB  |  182 lines

  1. /* PROGRAM : AutoIconOpen.c
  2.    AUTHOR  : Tony (**all at sea in C**) Wills.
  3.    DATE    : 15 FEB 87.
  4.    VERSION : 1.2
  5.    PURPOSE : To fool WorkBench into thinking it is recieving mouse inputs
  6.              that select & open icons.
  7.              Original application was to automatically open your disk icon
  8.              on bootup (Could be easily expanded to click open a file
  9.              of instructions as well).  For use in our NewsDisk
  10.              (=newsletter on a disk, like JumpDisk and Amigazine).
  11.    USE :
  12.    1) Install "AutoIconOpen" in your Workbench (or other bootable disk)
  13.       "c:" directory.
  14.    2) Put the command "AutoIconOpen" into your startup-sequence after
  15.       "LoadWB". You may possibly need a slight delay (use "Wait" command)
  16.       in between, to ensure that Workbench is up and going before this runs
  17.    3) Boot your disk and this program will then blindly try and double
  18.       click on whatever disk icon is sitting in the upper right hand corner
  19.       (that is the 'default' position for the first disk icon) of your
  20.       screen.
  21.    NB The disk icon that normally resides in the upper right hand corner
  22.       of your screen will be that of df0: if thats the only disk inserted
  23.       at LoadWB time.  If you have something in df1: Workbench will put
  24.       it's icon in that position with that of df0: below it.  Hence this
  25.       program will open df1: instead of df0:.
  26.  
  27.    This is a very simplistic program, and ignores all sorts of conventions
  28.    that might otherwise ensure it will work in many different environments.
  29.    (Just like the examples in the Amiga Technical manuals !!!, which this
  30.     program is based on.)
  31.    1) It assumes that the screen is 640x200 on startup
  32.    2) It assumes there is a cli window in front with it's bottom corner
  33.       at 640/400. It resizes this window to 540x200
  34.    3) This is expected to expose the disk icons residing in the top right
  35.       hand corner of the screen.
  36.    4) It opens the icon in the top righthand position by sending a double
  37.       click sequence.
  38.    5) All done, so closes input.device and exits.
  39.  
  40.    Bugs, oversights, and possible improvements :
  41.    1) Doesn't allocate anything in public address space so won't work on
  42.       future hardware with a MMU that stops programs getting at others
  43.       address space - I'm sure that this is the least of this programs
  44.       problems!
  45.    2) I thought I was working on a 640x200 screen but have to move twice
  46.       as far vertically as I would expect!
  47.    3) Could string all events together using ie_NextEvent pointers, but not
  48.       much point for this application.
  49.    4) If some twit moves the mouse during the execution of this program,
  50.       then who knows where it will end up.  Perhaps stringing all the
  51.       events together (as in 3. above) would ensure these spurious
  52.       movements didn't interfere.
  53.  
  54.    Revisions : 8 JUN 87
  55.         : Inserted CreatePort, so the the system had somewhere to reply
  56.    to messages, which we then ignore!  Lettuce C (Aka Lattice C) has this
  57.    CreatePort thing but it's not a standard system call, so couldn't add
  58.    this to the Assembler version - case of not enough documentation and not
  59.    knowing what I'm doing anyway.
  60.         Added bit to blat pointer into top left corner (0,0) first (it's
  61.    normally there on bootup anyway) just to make sure we get where we want
  62.    to go with relative pointer movement (haven't got around to pinning
  63.    down absolute pointer positioning commands).  And don't go hard into
  64.    bottom right corner (640,400) but stop at (638,398) to ensure we really
  65.    are sitting on the sizing gadget (or where it should be).
  66.    It now works under AmigaDOS 1.1 and 1.2.
  67. */
  68.  
  69. #include <exec/types.h>
  70. #include <exec/io.h>
  71. #include <devices/input.h>
  72. #include <exec/devices.h>
  73. #include <devices/inputevent.h>
  74.  
  75. #include <exec/ports.h>
  76.  
  77. struct MsgPort    *inputDevPort;
  78. struct IOStdReq   *input_request_block;
  79. struct InputEvent  SimulatedEvent;
  80.  
  81. extern struct MsgPort *CreatePort();
  82. extern struct IOStdReq *CreateStdIO();
  83.  
  84. main()
  85. {
  86.   if ((inputDevPort = CreatePort(0,0)) == NULL) exit(-1);
  87.   if ((input_request_block = CreateStdIO(inputDevPort)) == 0) exit (-2);
  88.   if (OpenDevice("input.device",0,input_request_block,0) != 0) exit(-1);
  89.  
  90. input_request_block->io_Command = IND_WRITEEVENT;
  91. input_request_block->io_Flags   = 0;
  92. input_request_block->io_Length  = sizeof(struct InputEvent);
  93. input_request_block->io_Data    = (APTR)&SimulatedEvent;
  94.  
  95. /* Blat pointer into top, lefthand corner, doesn't really matter where
  96.    we start from. I thought IECLASS_POINTERPOS or setting ie_Qualifier to
  97.    0 might give me absolute positioning - but didn't seem to do what I
  98.    expected.  Press left button when you get there */
  99. SimulatedEvent.ie_NextEvent          = NULL;
  100. SimulatedEvent.ie_Class              = IECLASS_RAWMOUSE;
  101. SimulatedEvent.ie_TimeStamp.tv_secs  = 0;
  102. SimulatedEvent.ie_TimeStamp.tv_micro = 0;
  103. SimulatedEvent.ie_Code               = IECODE_NOBUTTON;
  104. SimulatedEvent.ie_Qualifier          = IEQUALIFIER_RELATIVEMOUSE;
  105. SimulatedEvent.ie_X                  = -640;
  106. SimulatedEvent.ie_Y                  = -512; /*Might be on a PAL screen*/
  107.  
  108. DoIO(input_request_block);
  109.  
  110. /* Blat pointer into bottom, righthand corner, Press left button when you
  111.    get there */
  112. SimulatedEvent.ie_NextEvent          = NULL;
  113. SimulatedEvent.ie_Class              = IECLASS_RAWMOUSE;
  114. SimulatedEvent.ie_TimeStamp.tv_secs  = 0;
  115. SimulatedEvent.ie_TimeStamp.tv_micro = 0;
  116. SimulatedEvent.ie_Code               = IECODE_LBUTTON;
  117. SimulatedEvent.ie_Qualifier          = IEQUALIFIER_RELATIVEMOUSE;
  118. SimulatedEvent.ie_X                  = 638;
  119. SimulatedEvent.ie_Y                  = 398;
  120.  
  121. DoIO(input_request_block);
  122.  
  123. /* Move left 100 while holding left button down, and release button - ie
  124.    resize the CLI window I expect to be there - If nothing's there then
  125.    it doesn't really matter!  */
  126. SimulatedEvent.ie_NextEvent          = NULL;
  127. SimulatedEvent.ie_Class              = IECLASS_RAWMOUSE;
  128. SimulatedEvent.ie_TimeStamp.tv_secs  = 0;
  129. SimulatedEvent.ie_TimeStamp.tv_micro = 0;
  130. SimulatedEvent.ie_Code               = IECODE_LBUTTON | IECODE_UP_PREFIX;
  131. SimulatedEvent.ie_Qualifier          = IEQUALIFIER_RELATIVEMOUSE;
  132. SimulatedEvent.ie_X                  = -100;
  133. SimulatedEvent.ie_Y                  = 0;
  134.  
  135. DoIO(input_request_block);
  136.  
  137. /* Move to where I expect disk icon to be (595,22), but note I seem to
  138.    have to move to (595,45) as though the vertical resolution is double
  139.    what I think it is! */
  140. SimulatedEvent.ie_NextEvent          = NULL;
  141. SimulatedEvent.ie_Class              = IECLASS_RAWMOUSE;
  142. SimulatedEvent.ie_TimeStamp.tv_secs  = 0;
  143. SimulatedEvent.ie_TimeStamp.tv_micro = 0;
  144. SimulatedEvent.ie_Code               = IECODE_NOBUTTON;
  145. SimulatedEvent.ie_Qualifier          = IEQUALIFIER_RELATIVEMOUSE;
  146. SimulatedEvent.ie_X                  = 55;
  147. SimulatedEvent.ie_Y                  = -355;
  148.  
  149. DoIO(input_request_block);
  150.  
  151. /* Press left button without moving */
  152. SimulatedEvent.ie_NextEvent          = NULL;
  153. SimulatedEvent.ie_Class              = IECLASS_RAWMOUSE;
  154. SimulatedEvent.ie_TimeStamp.tv_secs  = 0;
  155. SimulatedEvent.ie_TimeStamp.tv_micro = 0;
  156. SimulatedEvent.ie_Code               = IECODE_LBUTTON;
  157. SimulatedEvent.ie_Qualifier          = IEQUALIFIER_RELATIVEMOUSE;
  158. SimulatedEvent.ie_X                  = 0;
  159. SimulatedEvent.ie_Y                  = 0;
  160.  
  161. DoIO(input_request_block);
  162.  
  163. /* Press left button again. Note I didn't release button in between but it
  164.    doesn't seem to matter! */
  165. SimulatedEvent.ie_NextEvent          = NULL;
  166. SimulatedEvent.ie_Class              = IECLASS_RAWMOUSE;
  167. SimulatedEvent.ie_TimeStamp.tv_secs  = 0;
  168. SimulatedEvent.ie_TimeStamp.tv_micro = 0;
  169. SimulatedEvent.ie_Code               = IECODE_LBUTTON;
  170. SimulatedEvent.ie_Qualifier          = IEQUALIFIER_RELATIVEMOUSE;
  171. SimulatedEvent.ie_X                  = 0;
  172. SimulatedEvent.ie_Y                  = 0;
  173.  
  174. DoIO(input_request_block);
  175.  
  176. /* All done so pack up and go home */
  177. CloseDevice(input_request_block);
  178. }
  179. /* Ok, you're right, it's the most over documented, painful program that
  180. you've ever seen!  But it's only my second attempt at C programs for the
  181. Amiga, and it does actually do what I want. */
  182.